package json

import (
	"encoding/json"
	"github.com/json-iterator/go"
)

//alias of json lib
var (
	Marshal             = jsoniter.ConfigCompatibleWithStandardLibrary.Marshal
	MarshalToString     = jsoniter.ConfigCompatibleWithStandardLibrary.MarshalToString
	Unmarshal           = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal
	UnmarshalFromString = jsoniter.ConfigCompatibleWithStandardLibrary.UnmarshalFromString
)

//Std 切换到标准库
func Std() {
	Marshal = json.Marshal
	MarshalToString = func(v interface{}) (string, error) {
		data, err := json.Marshal(v)
		return string(data), err
	}
	Unmarshal = json.Unmarshal
	UnmarshalFromString = func(str string, v interface{}) error {
		return json.Unmarshal([]byte(str), v)
	}
}

//Iterator 切换到jsoniter库
func Iterator() {
	Marshal = jsoniter.ConfigCompatibleWithStandardLibrary.Marshal
	MarshalToString = jsoniter.ConfigCompatibleWithStandardLibrary.MarshalToString
	Unmarshal = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal
	UnmarshalFromString = jsoniter.ConfigCompatibleWithStandardLibrary.UnmarshalFromString
}
